/**
 * @file iic_oled_clock.c
 * @author WaterFairy (995637517@qq.com)
 * @brief
 * @version 1.0.0
 * @date 2022-06-26 15:06:84
 *
 * @copyright Copyright (c) 2022
 *
 */
#include "iic_oled.h"
#include "iic_oled_clock.h"
#include "font_module.h"
#include <wiringPi.h>
#include <stdio.h>
#define TIME_PAGE 3
#define TIME_COLUMN 32

uint8_t clock_time[] = { 16, 52, 00 };

void iic_oled_clock_init(void)
{
    iic_oled_init();

    uint32_t time = clock_time[0] * 60 * 60 + clock_time[1] * 60 + clock_time[2];
    // unsigned time_start = millis();
    while (1)
    {
        unsigned time_start = millis();
        iic_oled_clock_set_time(time++);
        printf("dTime:%d\n", millis() - time_start);
        delayMicroseconds(1000000);
    }
}


void iic_oled_clock_set_time(uint32_t time_sec)
{
    uint8_t sec = time_sec % 60;
    uint8_t min = time_sec / 60 % 60;
    uint8_t hour = time_sec / 60 / 60 % 24;
    uint8_t column_date_start = 8;

    iic_oled_printf_position(0, column_date_start, "%d", 2022);
    iic_oled_display(0, 2, column_date_start + 32, 16, font_time[0]);
    iic_oled_printf_position(0, column_date_start + 48, "%d%d", 0, 6);
    iic_oled_display(0, 2, column_date_start + 64, 16, font_time[1]);
    iic_oled_printf_position(0, column_date_start + 80, "%d", 26);
    iic_oled_display(0, 2, column_date_start + 96, 16, font_time[2]);

    iic_oled_printf_position(TIME_PAGE, TIME_COLUMN, "%d%d:%d%d:%d%d", hour / 10, hour % 10, min / 10, min % 10, sec / 10, sec % 10);
}
